package cool.taomu.software.fig.utils

import java.text.DecimalFormat

class ShowUtils {
    def static void main(String[] args){
       println(sizeDescription(120066048));
    }
    def static sizeDescription(long size) {
        var format = new DecimalFormat("###.0");
        if (size >= 1024 * 1024 * 1024) {
            var result = (size / (1024.0 * 1024.0 * 1024.0));
            return #[format.format(result), "GB"].join()
        } else if (size >= 1024 * 1024) {
            var result = (size / (1024.0 * 1024.0));
            return #[format.format(result), "MB"].join()
        } else if (size >= 1024) {
            var result = (size / 1024.0);
            return #[format.format(result), "KB"].join()
        } else if (size < 1024) {
            if (size <= 0) {
                return "0B";
            } else {
                return #[size, "B"].join();
            }
        }
    }
}
